﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
 }
 <div class="layuimini-container">
     <div class="layuimini-main">
         <fieldset class="table-search-fieldset">
             <div style="margin: 5px 5px 5px 5px">

                 <form class="layui-form layui-form-pane" action="">
                     <div class="layui-form-item">
                         <div class="layui-inline">
                             <label class="layui-form-label required">新闻类别:</label>
                             <div class="layui-input-block">
                                 <select id="CategoryId" name="CategoryId" lay-filter="CategoryId" lay-search>
                                     <option value="">请选择</option>
                                 </select>
                             </div>
                         </div>
                         <div class="layui-inline">
                             <label class="layui-form-label">关键字:</label>
                             <div class="layui-input-inline">
                                 <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                             </div>
                         </div>
                         <div class="layui-inline">
                             <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                         </div>
                     </div>
                 </form>
             </div>
         </fieldset>
         <script type="text/html" id="toolbarDemo">
             <div class="layui-btn-container" id="toolbar">
                 <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                 <button id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                 <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                 <button id="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
             </div>
         </script>
         <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
     </div>
 </div>
 <script>
     layui.use(['jquery', 'form', 'table', 'common', 'tablePlug', 'treeTable', 'miniTab','layer'], function () {
         var $ = layui.jquery,
             form = layui.form,
             layer = layui.layer,
             table = layui.table,
             treetable = layui.treeTable,
             miniTab = layui.miniTab,
             common = layui.common;
             var loading = layer.load(0, { shade: false });
         common.rendertable({
             elem: '#currentTableId',
             url: '/ContentManage/ArticleNews/GetGridJson',
             sqlkey: 'F_Id',//数据库主键
             cols: [[
                 { field: 'F_Id', title: 'ID', sort: true, hide: true, hideAlways: true },
                 //此处需修改
                 { field: 'F_CategoryName', title: '新闻类别', width: 120 },
                 { field: 'F_Title', title: '标题', width: 160 },
                 { field: 'F_Zhaiyao', title: '摘要', width: 220 },
                 { field: 'F_SortCode', title: '排序', width: 80 },
                 {
                     field: 'F_IsTop', title: '置顶', width: 80, 
                     templet: function (d) {
                         if (d.F_IsTop == true) {
                             return "<input type='checkbox' checked='' lay-skin='primary' name='true' valuer='true'>";
                         } else {
                             return "<input type='checkbox' name='false'  lay-skin='primary' valuer='false'>";
                         }
                     }
                 },
                 {
                     field: 'F_IsHot', title: '热门', width: 80,
                     templet: function (d) {
                         if (d.F_IsHot == true) {
                             return "<input type='checkbox' checked='' lay-skin='primary' name='true' valuer='true'>";
                         } else {
                             return "<input type='checkbox' name='false'  lay-skin='primary' valuer='false'>";
                         }
                     }
                 },
                 { field: 'F_Click', title: '点击次数', width: 100 },
                 { field: 'F_Source', title: '来源', width: 120 },
                 { field: 'F_Author', title: '作者', width: 120 },
                 {
                     field: 'F_CreatorTime', title: '创建时间', minWidth: 100,
                     templet: function (d) {
                         if (d.F_CreatorTime) {
                             var time = new Date(d.F_CreatorTime);
                             return time.Format("yyyy-MM-dd hh:mm:ss");
                         }
                     }
                 },
                 { field: 'F_CreatorUserId', title: '创建人', minWidth: 120, hide: true, hideAlways: true }
             ]],
             done: function () {
                 //权限控制
                 common.authorizeButton("toolbar");
                 //关闭加载
                 layer.closeAll('loading');

             }
         });
         $(function () {
             initControl();
             form.render();
         });
         function initControl() {
             //绑定数据源
             //类型为下拉框时
             $("#CategoryId").bindSelect({
                 url: "/ContentManage/ArticleCategory/GetListJson",
                 id: "F_Id",
                 text: "F_FullName",
                 search: true,
             });
         }
         var entity;
         // 监听搜索操作
         form.on('submit(data-search-btn)', function (data) {
             //执行搜索重载
             common.reloadtable({
                 elem: 'currentTableId',
                 curr: 1,
                 where: { CategoryId: data.field.CategoryId,keyword: data.field.txt_keyword}
             });
             entity = null;
             return false;
         });
         table.on('row(currentTableFilter)', function (obj) {
             obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
             entity = obj;
         })
         //toolbar监听事件
         table.on('toolbar(currentTableFilter)', function (obj) { 
             if (obj.event === 'add') {  // 监听添加操作
                 miniTab.openNewTabByIframe({
                     title: "添加文章",
                     href: "/ContentManage/ArticleNews/Form",
                 });
             }
             else if (obj.event === 'delete') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.deleteForm({
                     url: "/ContentManage/ArticleNews/DeleteForm",
                     param: { keyValue: entity.data.F_Id },
                     success: function () {
                         common.reload('data-search-btn');
                   }
               });
           }
           else if (obj.event === 'edit') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.openNewTabByIframe({
                     title: "编辑文章",
                     href: "/ContentManage/ArticleNews/Form?keyValue=" + entity.data.F_Id,
                 });
           }
           else if (obj.event === 'details') {
                 if (entity == null) {
                     common.modalMsg("未选中数据", "warning");
                     return false;
                 }
                 common.openNewTabByIframe({
                     title: "查看文章",
                     href: "/ContentManage/ArticleNews/Details?keyValue=" + entity.data.F_Id,
                 });
           }
           return false;
       });
   });
</script>
